#ifndef DBQUERYBASETHREAD_H
#define DBQUERYBASETHREAD_H

#include <QObject>
#include "cnsMacroGlobal.h"
#include <QThread>
#include "cnsComponent.h"

class DbQueryBaseThread : public CnsComponent {
    Q_OBJECT
public:
    DbQueryBaseThread()
        : m_workThread(new QThread())
    {
    }
    DbQueryBaseThread(QThread *thread)
        : m_workThread(thread)
    {
    }


    virtual ~DbQueryBaseThread() override
    {
        m_workThread->quit();
        m_workThread->wait();
    }
    inline bool isDead()
    {
        return _isDead;
    }
    inline bool isStop()
    {
        return _isDead || _isForceStop;
    }
    inline QScopedPointer<QThread>& getWorkThread()
    {
        return m_workThread;
    }
    inline QVariantHash& getProps()
    {
        return _props;
    }
    inline void setDead(bool isDead)
    {
        _isDead = isDead;
    }
    inline void forceStop()
    {
        _isForceStop = true;
    }
    inline void setForceStop(bool isForceStop)
    {
        _isForceStop = isForceStop;
    }
    inline bool isForceStop()
    {
        return _isForceStop;
    }
    inline void setProps(const QVariantHash &props)
    {
        _props = props;
    }

signals:

    void dbQueryThreadFinished(CnsComponentPtr com);

protected:
    QScopedPointer<QThread> m_workThread;

    QVariantHash _props;
    bool _isForceStop = false;//forceStop can't run callback function
    bool _isDead = false;//dead can run callback function

};

CNS_COM_DECL_METATYPE(DbQueryBaseThread)

typedef QSet<DbQueryBaseThread*> DBQUERYBASETHREADPTRSET;

#endif  // DBQUERYBASETHREAD_H
